library SniperTraining initializer init requires LegacySystem

	private function Trig_Marskmanship_Learn_Conditions takes nothing returns boolean
		if ( not ( GetLearnedSkillBJ() == 'A06Z' ) ) then
			return false
		endif
		return true
	endfunction

	private function Trig_Marskmanship_Learn_Actions takes nothing returns nothing
		local unit u = GetTriggerUnit()
		local player p = GetOwningPlayer(u)
		local integer levelofm = GetUnitAbilityLevelSwapped('A06Z', u)

		if(levelofm == 1) then
		   call SetUnitAcquireRangeBJ( u,  2800 )
		   call SetPlayerTechResearchedSwap( 'R010', 1, p ) // + 800 range
		endif

		if(levelofm == 2) then
		   call UnitAddAbility(u, 'A08O') // camo
		endif

		if(levelofm == 3) then
		   // do nothing ( scope is triggered to check the level of this ability)
		endif

		if(levelofm == 4) then
		   call SetPlayerTechResearchedSwap( 'R012', 1, p ) // laser des
		endif

		if(levelofm == 5) then
		   call SetUnitAcquireRangeBJ( u,  3600 )
		   call SetPlayerTechResearchedSwap( 'R011', 1, p )  
		   set u = null
		   set p = null
		   call DestroyTrigger(GetTriggeringTrigger()) 
		endif

		set u = null
		set p = null
	endfunction

	private function init takes nothing returns nothing
		local trigger t
		set t = CreateTrigger(  )
		call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_HERO_SKILL )
		call TriggerAddCondition( t, Condition( function Trig_Marskmanship_Learn_Conditions ) )
		call TriggerAddAction( t, function Trig_Marskmanship_Learn_Actions )
	endfunction

endlibrary

